package hot100;

import java.util.HashSet;
import java.util.Set;

public class Lc3 {
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.isEmpty()) return 0;
        Set<String> set = new HashSet<>();
        int right = 0;
        int res = 0;
        String[] split = s.split("");
        for (int left = 0; left < split.length; left++) {
            if (right < split.length && set.contains(split[right])) {
                set.remove(split[left - 1]);
            }
            while (right < split.length && !set.contains(split[right])) {
                set.add(split[right]);
                right++;
            }
            res = Math.max(res, right - left);
        }
        return res;
    }

    public static void main(String[] args) {
        Lc3 lc3 = new Lc3();
        System.out.println(lc3.lengthOfLongestSubstring("aab"));
    }
}
